package cn.hnucm.orderservice.service.impl;

import cn.hnucm.orderservice.entity.TbLog;
import cn.hnucm.orderservice.mapper.TbLogMapper;
import cn.hnucm.orderservice.service.TbLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 系统日志 服务实现类
 * </p>
 *
 * @author chenjintao
 * @since 2021-12-06
 */
@Service
public class TbLogServiceImpl extends ServiceImpl<TbLogMapper, TbLog> implements TbLogService {

    @Autowired
    private TbLogMapper tbLogMapper;

    /**
     * 添加一条Log记录
     * @param tbLog
     * @return
     */
    @Transactional
    @Override
    public Boolean addLog(TbLog tbLog) {
        return tbLogMapper.insert(tbLog)>0;
    }


    /**
     * 通过Id删除一条Log记录
     * @param logId
     * @return
     */
    @Transactional
    @Override
    public Boolean deleteLogById(Integer logId) {
        return tbLogMapper.deleteById(logId)>0;
    }

    /**
     *
     * 查询所有的Log，按照page分页
     * @return
     */
    @Transactional
    @Override
    public IPage<TbLog> seleteLogByPage(Integer pageSize, Integer currentPage) {
        Page<TbLog> tbLogPage = new Page<>(currentPage,pageSize);
        return tbLogMapper.selectPage(tbLogPage,null);
    }

    /**
     *
     * 查询一条Log
     * @param logId
     * @return
     */
    @Transactional
    @Override
    public TbLog selectLogById(Integer logId) {
        return tbLogMapper.selectById(logId);
    }
}
